package com.eduction.modules.system.dao;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.eduction.common.dbutil.DbHelper;
import com.eduction.modules.system.entity.SurveyProblem;

@Repository
public class SurveyProblemRepository {

	@Autowired
	private DbHelper dbHelper;
	@Autowired
	private SurveyProblemDao surveyProblemDao;
	
	/**
	 * 保存
	 */
	public void saveSurveyProblem(SurveyProblem s){
		surveyProblemDao.save(s);
	}
	
	/**
	 * 查询
	 * @throws SQLException 
	 */
	public SurveyProblem querySurveyProblemData(String expertId, String itemId, String schoolId,String expertTypeId) throws SQLException{
		String sql = "SELECT * FROM t_survey_problem where s_expert_id = ? and s_item_id = ? and s_school_id = ?  and s_type = ? ";
		return dbHelper.getBean(sql, SurveyProblem.class, expertId,itemId,schoolId,expertTypeId);
		
	}

	/**
	 * 查询(总)
	 * @throws SQLException
	 */
	public List<SurveyProblem> querySurveyProblemData(String itemId, String schoolId,String expertTypeId) throws SQLException{
		String sql = "SELECT * FROM t_survey_problem where s_item_id = ? and s_school_id = ?  and s_type = ? order by s_create_time desc";
		return dbHelper.getBeanList(sql, SurveyProblem.class,itemId,schoolId,expertTypeId);

	}

	public void deleteSurveyProblem(String expertId, String schoolId, String itemId,String expertTypeId) throws SQLException {
		String sql = "delete FROM t_survey_problem where (s_expert_id = ? and s_school_id = ? and s_item_id = ? and s_type = ? )";
		dbHelper.execute(sql, expertId,schoolId,itemId,expertTypeId);
	}
}
